<?php
	
	if(isset($_POST['username']) && !empty($_POST['username'])){
		$username=$_POST['username'];
		$password=$_POST['password'];

		//查询数据库
		$link=mysqli_connect("localhost","root","","demo");
		// var_dump($link);exit();
		$sql="select count(*) from admin where username='$username' and password='$password'";
		// var_dump($sql);exit();
		$result = mysqli_query($link,$sql); 		
		$result=mysqli_fetch_row($result);
		if($result[0]==1){
			//登录成功
			session_start();		//开启session
			$_SESSION['username']=$username;		//存储session
			
			header("location:/index.php");
		}else{
			//登录失败
			header("location:/login.php");
		}
	}
?>



<!DOCTYPE html>
<html>
<head>
	<title>登录</title>
	<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css">
</head>
<body>
	<div class="container">
		<h1>登录</h1>
		<div class="col-lg-5">
			<form action="./login.php" method="post">
				<div class="form-group">
					<label>用户名：</label>
					<input type="text" class="form-control" name="username" />
				</div>
				<div  class="form-group">
					<label>密码：</label>
					<input type="password" class="form-control" name="password" />
				</div>
				<input type="submit" value="提交" class="btn btn-success" />
			</form>

		</div>
		
	</div>
	
</body>
</html>